//
//  leftChoiceViewController.m
//  EducationAdminClient
//
//  Created by KWSD_F on 16/4/5.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "leftChoiceViewController.h"
#import "UIColor+CL.h"

@interface leftChoiceViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *_dataArr;
    UITableView *_myTableView;
}
@end

@implementation leftChoiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =  [UIColor colorWithHex:0xf4f4f4];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav2"] forBarMetrics:UIBarMetricsDefault];
    // Do any additional setup after loading the view.
    _dataArr = [NSMutableArray array];
    UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftNavBtn.frame = CGRectMake(0, 0, 11, 37/2);
    [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
    [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
    self.navigationItem.leftBarButtonItem = item;
    for (int i = 0; i<10; i++) {
        [_dataArr addObject:[NSString stringWithFormat:@"数据%d",i]];
    }
    _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_myTableView];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.allowsSelection = YES;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma - mark tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cellId";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    
    //.....
    
    //  indexPath代表cell的位置
    //  indexPath.section代表在第几段
    //  indexPath.row代表在第几行
    
    NSLog(@"section = %zd,row = %zd",indexPath.section,indexPath.row);
    
    //通过cell的位置找到对应的保存数据的对象（数据模型）
    
    //将对应的信息展示在cell自带的2个label上
    cell.textLabel.text = _dataArr[indexPath.row];
    
    
    
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%zd",_path);
    
    
    
    [self.delegate sendText:_dataArr[indexPath.row]andPath:_path];
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        
    }];
}


-(void)LeftClick:(UIButton *)btn{
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
